<!DOCTYPE html>
<!--
Copyright 2017 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->

<link rel="import" href="/dashboard/elements/speed-releasing-alerts.html">
<link rel="import" href="/dashboard/static/simple_xhr.html">
<link rel="import" href="/dashboard/static/testing_common.html">

<link rel="import" href="/tracing/base/unit.html">
<link rel="import" href="/tracing/core/test_utils.html">

<script>
'use strict';

tr.b.unittest.testSuite(function() {
  const testOptions = {
    setUp() {
      d.BUG_DETAILS.reset();
      d.BUG_DETAILS.populateForTest(new Map([
        [12345, Promise.resolve(mockBug)],
        [54321, Promise.resolve(mockBug)],
      ]));
    },
    tearDown() {
      testing_common.clearXhrMock();
    }
  };

  const anomalies = [{
    'end_revision': 395930,
    'dashboard_link': '\/do-not-click',
    'bug_id': null,
    'key': 'agxzfmNocm9tZXBlcmZyFAsSB0Fub21hbHkYgICg7IDjvgkM',
    'date': '2016-05-26',
    'median_before_anomaly': 0.0013427734375,
    'bisect_status': null,
    'testsuite': 'browser_tests',
    'group': 'agxzfmNocm9tZXBlcmZyFwsSCkFsZXJ0R3JvdXAYgICg7PLrvgsM',
    'start_revision': 395893,
    'bot': 'win10',
    'improvement': false,
    'median_after_anomaly': 0.007778930664065,
    'master': 'ChromiumPerf',
    'percent_changed': '479.3%',
    'absolute_delta': '1234.56789',
    'units': 'kb',
    'test': 'audio_rates_recvonly\/expand_rate',
    'recovered': false
  },
  {
    'end_revision': 395900,
    'dashboard_link': '\/do-not-click',
    'bug_id': null,
    'key': 'agxzfmNocm9tZXBlcmZyFAsSB0Fub21hbHkYgICgrP-CtAkM',
    'date': '2016-05-26',
    'median_before_anomaly': 0.000518798828125,
    'bisect_status': null,
    'testsuite': 'browser_tests',
    'group': 'agxzfmNocm9tZXBlcmZyFwsSCkFsZXJ0R3JvdXAYgICg7PLrvgsM',
    'start_revision': 395893,
    'bot': 'win10',
    'improvement': false,
    'median_after_anomaly': 0.0044677734375,
    'master': 'ChromiumPerf',
    'percent_changed': '761.2%',
    'absolute_delta': '4321000.01234',
    'units': 'kb',
    'test': 'audio_rates\/expand_rate\/',
    'recovered': false
  },
  {
    'end_revision': 395895,
    'dashboard_link': '\/do-not-click',
    'bug_id': null,
    'key': 'agxzfmNocm9tZXBlcmZyFAsSB0Fub21hbHkYgICg7IqyqAoM',
    'date': '2016-05-25',
    'median_before_anomaly': 0.00159301757813,
    'bisect_status': null,
    'testsuite': 'browser_tests',
    'group': 'agxzfmNocm9tZXBlcmZyFwsSCkFsZXJ0R3JvdXAYgICg7PLrvgsM',
    'start_revision': 395894,
    'bot': 'linux',
    'improvement': false,
    'median_after_anomaly': 0.00677490234375,
    'master': 'ChromiumPerf',
    'percent_changed': '325.3%',
    'absolute_delta': '12.00034',
    'units': 'count',
    'test': 'audio_rates_recvonly\/expand_rate',
    'recovered': false
  },
  {
    'end_revision': 395895,
    'dashboard_link': '\/do-not-click',
    'bug_id': null,
    'key': 'agxzfmNocm9tZXBlcmZyFAsSB0Fub21hbHkYgICg7KzCrAoM',
    'date': '2016-05-25',
    'median_before_anomaly': 0.0007232666015625,
    'bisect_status': null,
    'testsuite': 'browser_tests',
    'group': 'agxzfmNocm9tZXBlcmZyFwsSCkFsZXJ0R3JvdXAYgICg7PLrvgsM',
    'start_revision': 395894,
    'bot': 'linux',
    'improvement': false,
    'median_after_anomaly': 0.00344543457031,
    'master': 'ChromiumPerf',
    'percent_changed': '376.4%',
    'absolute_delta': '1.21578',
    'units': 'runs/s',
    'test': 'audio_rates\/expand_rate',
    'recovered': false
  },
  {
    'end_revision': 395237,
    'dashboard_link': '\/do-not-click',
    'bug_id': 12345,
    'key': 'agxzfmNocm9tZXBlcmZyFAsSB0Fub21hbHkYgICgzOSBpgoM',
    'date': '2016-05-21',
    'median_before_anomaly': 9046443.9,
    'bisect_status': null,
    'testsuite': 'browser_tests',
    'group': 'agxzfmNocm9tZXBlcmZyFwsSCkFsZXJ0R3JvdXAYgICgrKCEsQoM',
    'start_revision': 395226,
    'bot': 'mac',
    'improvement': false,
    'median_after_anomaly': 13144744.3,
    'master': 'ChromiumPerf',
    'percent_changed': '45.3%',
    'absolute_delta': '1.22448',
    'units': 'ms',
    'test': 'video_total_bytes_H264\/bytes_sent',
    'recovered': false
  },
  {
    'end_revision': 395238,
    'dashboard_link': '\/do-not-click',
    'bug_id': 54321,
    'key': 'agxzfmNocm9tZXBlcmZyFAsSB0Fub21hbHkYgIChzORBpgoM',
    'date': '2016-05-21',
    'median_before_anomaly': 9046443.9,
    'bisect_status': null,
    'testsuite': 'browser_tests',
    'group': 'agxzfmNocm9tZXBlcmZyFwsSCkFsZXJ0R3JvdXyYgICgrKCEsQoM',
    'start_revision': 395238,
    'bot': 'mac',
    'improvement': false,
    'median_after_anomaly': 13144744.3,
    'master': 'ChromiumPerf',
    'percent_changed': '45.3%',
    'absolute_delta': '1.22448',
    'units': 'ms',
    'test': 'video_total_bytes_H264\/bytes_sent',
    'recovered': false
  },
  {
    'end_revision': 395213,
    'dashboard_link': '\/do-not-click',
    'bug_id': null,
    'key': 'agxzfmNocm9tZXBlcmZyFAsSB0Fub21hbHkYgICgjLewuwoM',
    'date': '2016-05-21',
    'median_before_anomaly': 8959675.6,
    'bisect_status': null,
    'testsuite': 'browser_tests',
    'group': 'agxzfmNocm9tZXBlcmZyFwsSCkFsZXJ0R3JvdXAYgICgzND5sAoM',
    'start_revision': 395207,
    'bot': 'mac',
    'improvement': false,
    'median_after_anomaly': 12987079.75,
    'master': 'ChromiumPerf',
    'percent_changed': '45.0%',
    'absolute_delta': '16789.11125',
    'units': 'ms',
    'test': 'video_total_bytes_H264\/bytes_sent',
    'recovered': false
  },
  {
    'end_revision': 395213,
    'dashboard_link': '\/do-not-click',
    'bug_id': null,
    'key': 'agxzfmNocm9tZXBlcmZyFAsSB0Fub21hbHkYgICgzPy7tgoM',
    'date': '2016-05-21',
    'median_before_anomaly': 8823510.6,
    'bisect_status': null,
    'testsuite': 'browser_tests',
    'group': 'agxzfmNocm9tZXBlcmZyFwsSCkFsZXJ0R3JvdXAYgICgzND5sAoM',
    'start_revision': 395207,
    'bot': 'mac',
    'improvement': false,
    'median_after_anomaly': 13323686.35,
    'master': 'ChromiumPerf',
    'percent_changed': '51.0%',
    'absolute_delta': '12345654545789.21548',
    'units': 'kb',
    'test': 'video_total_bytes_H264\/bytes_recv',
    'recovered': false
  }];
  const mockBug = {
    'review_urls': [
      'http://codereview.google.com/12345',
      'http://review.chromium.org/23435'
    ],
    'bisects': [
      {
        'status': 'failed',
        'metric': 'Total',
        'buildbucket_link': '/foo/bar',
        'bot': 'android-nexus5-perf-bisect'
      },
      {
        'status': 'started',
        'metric': 'Total',
        'buildbucket_link': '/foo/bar',
        'bot': 'windows-perf-bisect'
      },
    ],
    'owner': 'foo@bar.com',
    'published': '2017-02-17T23:08:44',
    'state': 'open',
    'status': 'Untriaged',
    'summary': 'A regression occurred! Oh no!',
    'comments': [
      {
        'author': 'foo@chromium.org',
        'published': '2017-02-17T23:08:44',
        'content': 'hello!'
      },
      {
        'author': 'bar@chromium.org',
        'published': '2017-02-17T23:08:44',
        'content': 'world!'
      }
    ]
  };

  test('instantiate', function() {
    const mockResponse = {
      'revisions': [1, 2],
      anomalies
    };
    uri.getPathName = function() { return ''; };
    testing_common.addXhrMock('/speed_releasing/undefined?anomalies=true',
        JSON.stringify(mockResponse));
    const page = document.createElement('speed-releasing-alerts');
    this.addHTMLOutput(page);
  }, testOptions);
});
</script>
